<?php
class ZoneAction extends CommonAction {
	//过滤查询字段
	//function _filter(&$map){
	//	$map['name'] = array('like',"%".$_POST['name']."%");
	//}
    /**
     +----------------------------------------------------------
     * 区域列表
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return void
     +----------------------------------------------------------
     * @throws FcsException
     +----------------------------------------------------------
     */
    public function zone()
    {
        //读取系统的用户列表
        $zone    =   D("Zone");
		$list=$zone->field('id,name')->select();
		
		//dump(	$user);
		foreach ($list as $vo){
			$userList[$vo['id']]	=	$vo['name'];
		}


        $this->assign('actionList',$userList);
        $this->display();

        return;
    }
    public function index()
    {
        $zone    =   D("Zone");
        $where['ztype']=0;
        $where['status']=1;
        $where['pid']=1;
		$list=$zone->where($where)->order('id')->select();
 
        //$zone ->cacheZone(1);       
        $this->assign('list',$list);
        $this->display();
        return;
    }    
    public function add()
    {
        //创建数据对象
        $Zone = D('Zone');
        //查找满足条件的列表数据
        $pId =  isset($_GET['pId'])?$_GET['pId']:1;
	$where['status']=1;
	$where['pid']=$pId;
        $list     = $Zone->where($where)->field('id,name')->select();
        foreach ($list as $vo){
			$zonesList[$vo['id']]	=	$vo['name'];
	}
        $this->assign('zonesList',$zonesList);
        $this->display();
        return;
    }
    public function addPlace()
    {
        //创建数据对象
        $Zone = D('Zone');
        //查找满足条件的列表数据
        $pId =  isset($_GET['pId'])?$_GET['pId']:1;
	$where['status']=1;
        $where['ztype']=0;
	$where['id']=$pId;
        $list     = $Zone->where($where)->field('id,name')->find();
        $zid=$list['id'];
        $name = $list['name'];
   
        $this->assign('zid',$zid);
         $this->assign('zname',$name);
        $this->display();
        return;
    } 
    public function getplacelist()
    {
        //创建数据对象
        $zone = D("ZoneView");

        $pId =  $_GET['pid'];
        $whereOne['ztype']=0;
        $whereOne['status']=1;
        $whereOne['id']=$pId ; ;
        $list  = $zone->where($whereOne)->field('id,name')->find();
        $zid=$list['id'];
        $name = $list['name'];
        $where['status']=1;
        $where['ztype']=1;
	$where['pid']=$pId ;
        if (!empty($zone)) {
            $this->_list($zone, $where,'id');
        }

 
        $this->assign('zid',$zid);
        $this->assign('zname',$name);
        //$this->assign('list',$list);
        Cookie::set('_currentUrl_', __SELF__);
        $this->display();
        return;
    }     
    function insert() {
        //B('FilterString');
        $name = $this->getActionName();
        $model = D($name);
        if (false === $model->create()) {
            $this->error($model->getError());
        }
        //保存当前数据对象
        $list = $model->add();
        if ($list !== false) { //保存成功
            $this->assign('jumpUrl', Cookie::get('_currentUrl_'));
             $model->cacheZone(1);
            $this->success('新增成功!');
        } else {
            //失败提示
            $this->error('新增失败!');
        }
    }

    //编辑区域信息
    public function edit() {
       $model = M("Zone");
        $id = $_REQUEST [$model->getPk()];

        $vo = $model->getById($id);
        $this->assign('vo', $vo);
	$where['status']=1;
        $where['ztype']=0;
	$where['pId']=1;
        $list     = $model->where($where)->field('id,name')->select();
        $zid=$list['id'];
        $name = $list['name'];
	 $this->assign('zid',$zid);
        $this->assign('zname',$name);
       
        $this->display();
    }
    //编辑商网信息
    public function editPlace() {
       $model = M("Zone");
        $id = $_REQUEST [$model->getPk()];

        $vo = $model->getById($id);
        $this->assign('vo', $vo);
	$where['status']=1;
        $where['ztype']=0;
	$where['id']= $_GET['pId'];
        $list     = $model->where($where)->field('id,name')->find();
        $zid=$list['id'];
        $name = $list['name'];
        $this->assign('zid',$zid);
        $this->assign('zname',$name);
        $this->display();
    }    



}
?>